''' 集合练习 '''

class OrderSet():
    def __init__(self,data):
        self.data = []
        for i in data:
            if i not in self.data:
                self.data.append(i)

        # print(self.data)

    def __repr__(self):
        return 'OrderSet(%r) ' % self.data

    def __and__(self, other):
        return OrderSet(
            (x for x in self.data if x in other.data)
        )

    def __or__(self, other):
        return OrderSet(
            self.data + other.data
        )

    def __xor__(self, other):
        return (self-other) | (other-self)

    def __sub__(self, other):
        return OrderSet(
            (x for x in self.data if x not in other.data)
        )

    def __eq__(self, other):
        return self.data == other.data

    def __ne__(self, other):
        return self.data != other.data

    def __contains__(self, item):
        return self.data in item


set1 = OrderSet([1,1,2,2,3,1,5,4,89,5,66,33,88,0])
set2 = OrderSet([9,8,6,88,33,55,2,1,1,3,77,55,4,43])

# print(set1)
# print(type(set1.data))
print(set1 & set2)
print(set1 | set2)
print(set1 ^ set2)
print(set1 - set2)
print(set1 == set2)
print(set1 != set2)
print(set1 in set2)
print(set1 not in set2)

